package com.andy.wan.android.mvp.ui.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.andy.wan.android.R;
import com.andy.wan.android.mvp.bean.BannerBean;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.bumptech.glide.request.RequestOptions;
import com.chad.library.adapter.base.BaseViewHolder;
import com.youth.banner.adapter.BannerAdapter;

/**
 * @Author: luofan
 * @CreateDate: 2020/3/25 18:26
 * @Description:
 */
public class HomeBannerAdapter extends BannerAdapter<BannerBean, BaseViewHolder> {

    public HomeBannerAdapter() {
        super(null);
    }

    @Override
    public BaseViewHolder onCreateHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.adapter_home_banner, parent, false);
        ViewGroup.LayoutParams lp = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
        view.setLayoutParams(lp);
        return new BaseViewHolder(view);
    }

    @Override
    public void onBindView(BaseViewHolder holder, BannerBean data, int position, int size) {
        ImageView img = holder.getView(R.id.img);
        Glide.with(img).load(data.getImagePath()).apply(RequestOptions.bitmapTransform(new RoundedCorners(16))).into(img);
        holder.setText(R.id.tv_title, data.getTitle());
    }
}
